package models;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SHA1 {
    
    public static String encrypt(String password) {
      MessageDigest digest;
      String hash = "";
      try {
          digest = MessageDigest.getInstance("SHA-1");
          digest.reset();
          digest.update(password.getBytes());
          byte[] bytes = digest.digest();
          
          for (int i = 0; i < bytes.length; i++) {
              hash += Integer.toString(( bytes[i] & 0xff ) + 0x100, 16).substring( 1 );
          }
      } catch (NoSuchAlgorithmException e) {
            System.out.println(e.toString());
      }
      return hash;
    }    
}